// 补全关键引入
import { createApp } from 'vue'
import App from './App.vue'
import router from './router' // 必须存在router目录
import ElementPlus from 'element-plus'
import * as ElementPlusIcons from '@element-plus/icons-vue'
import { createPinia } from 'pinia';
import 'element-plus/dist/index.css'
import '@/assets/styles/reset.css'
import './assets/styles/theme.css' // 导入全局主题样式
import i18n from './i18n'; // 引入 i18n
import http from '@/utils/http';
import { useAuthStore } from '@/stores';
import 'v-calendar/style.css';

// 创建应用
const app = createApp(App)
const pinia = createPinia()

// 注册 Pinia
app.use(pinia)

// 初始化认证状态
const authStore = useAuthStore()
authStore.checkAuth()

// 注册 Element Plus
app.use(ElementPlus, {
  locale: i18n.global.messages[i18n.global.locale.value]
})

// 注册 Element Plus 图标
for (const [key, component] of Object.entries(ElementPlusIcons)) {
  app.component(key, component)
}

// 注册 i18n
app.use(i18n)

// 注册路由
app.use(router)

// 注册全局属性
app.config.globalProperties.$http = http
app.config.globalProperties.$authStore = authStore

// 挂载应用
app.mount('#app')